<template>
  <div class="home-container">
    <!-- 导航栏 -->
    <van-nav-bar class="page-nav-bar" fixed>
      <van-button
        class="search-btn"
        slot="title"
        type="info"
        size="mini"
        round
        icon="search"
        :to="{name:'search'}"
        >搜索</van-button
      >
    </van-nav-bar>

    <!-- 频道列表 -->
    <van-tabs class="channel-tabs" v-model="active" animated swipeable>
      <van-tab
        :title="channel.name"
        v-for="channel in channels"
        :key="channel.id"
      >
        <!-- 文章列表 -->
        <article-list :channel="channel" />
        <!-- 文章列表 -->
      </van-tab>

      <div slot="nav-right" class="placeholder"></div>
      <div slot="nav-right" class="hbg-btn" @click="showPopup">
        <i class="iconfont icongengduo"></i>
      </div>
    </van-tabs>
    <!-- 频道编辑弹出层 -->
    <van-popup
      class="edit-channel-popup"
      v-model="show"
      position="bottom"
      round
      :style="{ height: '90%' }"
      closeable
      close-icon-position="top-left"
    >
      <!-- 传递channels -->
      <channel-edit :userChannels="channels" :active="active"  />
    </van-popup>
  </div>
</template>

<script>
// 获取频道列表 接口
// import { getUserChannels } from "@/api";
// import ArticleList from "./components/article-list";
// import ChannelEdit from "./components/channel-edit";

import { getUserChannels } from '@/api/user'
import ArticleList from './components/article-list'
import ChannelEdit from './components/channel-edit'
import { mapState } from 'vuex'
import { getItem } from '@/utils/storage'

export default {
  name: "HomeIndex",
  components: {
    ArticleList,
    ChannelEdit
  },
  data() {
    return {
      active: 0, // 频道列表
      channels: [],
      show: false
    };
  },
  computed: {
    ...mapState(['user'])
  },
  created() {
    this.loadChannels();
  },
  methods: {
    // 通过频道列表api 获取频道数组
    async loadChannels() {
      try {
        const { data } = await getUserChannels();
        this.channels = data.data.channels;
        console.log(1111, data.data.channels)
      } catch (err) {
        this.$toast("获取频道数据失败");
      }
    },
    showPopup() {
      this.show = true;
    }
  }
};
</script>

<style scoped lang="less">
.home-container {
  padding-top: 174px;
  padding-bottom: 100px;
  /* .van-nav-bar__title {
    max-width: unset; //在全局样式中使用，并提高权重
  } */
  .search-btn {
    width: 555px;
    height: 64px;
    background-color: #5babfb;
    border: none;
    font-size: 28px;
    .van-icon {
      font-size: 32px;
    }
  }

  /deep/ .channel-tabs {
    .van-tabs__content {
      min-height: 79vh;
    }
    .van-tabs__wrap {
      height: 82px;
      position: fixed;
      top: 92px;
      z-index: 1;
      left: 0;
      right: 0;
    }

    .van-tab {
      border-right: 1px solid #edeff3;
      min-width: 200px;
      font-size: 30px;
      color: #777777;
    }

    .van-tab--active {
      color: #333333;
    }

    /* .van-tabs__nav {
      padding-bottom: 0;
    } */

    .van-tabs__line {
      margin-bottom: 8px;
      width: 31px !important;
      height: 6px;
      background-color: #3296fa;
    }

    .placeholder {
      flex-shrink: 0;
      width: 66px;
      height: 82px;
    }

    .hbg-btn {
      position: fixed;
      right: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 66px;
      height: 82px;
      background-color: #fff;
      background-color: rgba(255, 255, 255, 0.902);
      i.iconfont {
        font-size: 33px;
      }
      &:before {
        content: "";
        position: absolute;
        left: 0;
        width: 1px;
        height: 58px;
        background-image: url(~@/assets/images/gradient-gray-line.png);
        background-size: contain;
      }
      /* .edit-channel-popup {
        padding-top: 100px;
        box-sizing: border-box;
      } */
    }
  }
}
</style>
